/*
 * schoolMapLocs : id, name, address, rating
 * schoolMapLocTopics : id, title, updateTime, createTime, postCount
 * schoolMapLocTopicPosts : id, topic_id, topic_title, content, createTime
 */

var LoginCtrl = new dojo.declare(null, {
	//constructor/destructor
	constructor : loginCtrl_constructor,
	destroy : loginCtrl_destructor,
	
	//methods
	init : loginCtrl_init
});

function loginCtrl_constructor(){
	var obj = this;
	obj._myList = null;
}

function loginCtrl_destructor(){
}

function loginCtrl_init(){
	function showMsg(item, msg, type){
		$.validationEngine.buildPrompt(item, msg, type);
		setTimeout("$.validationEngine.closePrompt('" + item + "');", 5000);
	}
	
	var obj = this;
	obj._myList = new TabList();
	obj._myList.init({baseItem : $("#mylist"), listName : "我的...", defaultTab : 0,
		normalTabHtml : "<div class='tab'><div class='normal'><a id='tab_name'></a></div></div>",
		currentTabHtml : "<div class='tab'><div class='selected'><a id='tab_name'></a></div></div>",
		tabs : [["地点", "/login/getSchoolMapLocs", {}, "/login/getSchoolMapLocCount", {}],
			["话题", "/login/getSchoolMapLocTopics", {}, "/login/getSchoolMapLocTopicCount", {}],
			["回复", "/login/getSchoolMapLocTopicPosts", {}, "/login/getSchoolMapLocTopicPostCount", {}]
		],
		emptyHtml : ["<div style='padding-left:10px;'>我还没有评价过地点...</div>", "<div style='padding-left:10px;'>我还没有创建过话题...</div>",
			"<div style='padding-left:10px;'>我还没有发表过回复...</div>"
		],
		itemHtml : [$("#mylist_item_maploc_example").html(), $("#mylist_item_topic_example").html(), $("#mylist_item_post_example").html()],
		itemHtmlMapping : [[[0, "loc_id", "attr_id"], [1, "loc_name", "text"], [2, "loc_address", "text"], [3, "loc_rating", "star"]],
			[[0, "topic_id", "attr_id"], [1, "topic_title", "text"], [2, "topic_maploc", "text"], [3, "topic_updatetime", "text"], [4, "topic_createtime", "text"], [5, "topic_postcount", "text"]],
			[[1, "topic_id", "attr_id"], [2, "post_topic_title", "text"], [3, "post_content", "text"], [4, "post_createtime", "text"]]
		],
		itemClicked : function(cur){
			if (obj._myList.curTab() == 0){
				var id = cur.find("#loc_id").attr("alt");
				window.location = "/map/maploc?id=" + id;
			}  else if (obj._myList.curTab() == 1 || obj._myList.curTab() == 2){
				var id = cur.find("#topic_id").attr("alt");
				window.location = "/map/maploc/topic?id=" + id;
			}  
		}
	});
	
	$("#link_apply_card").click(function(){
		showMsg("#link_apply_card", "正在提交申请，请稍候...", "load");
		$.post("/login/applyCard", function(data){
			if (data == "too fast"){
				showMsg("#link_apply_card", "您的申请提交过于频繁，请稍候提交。", "error");
			}  else if (data == "success"){
				showMsg("#link_apply_card", "申请提交成功。", "pass");
			}  
		}, "json");
	});
}

if (dojo.getObject("loginCtrl") == null) var loginCtrl = new LoginCtrl();
$(document).ready(function(){
	loginCtrl.init();
});
